/**
 * 
 */
package com.nba.common.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.springframework.core.io.support.PropertiesLoaderUtils;


public class PropertiesLoaderUtil {

	/**
	 * 属性文件加载方法
	 * @param resourceName
	 * @return
	 * @throws IOException
	 */
	public static Properties loadAllProperties(String resourceName)
			throws Exception {
	    //String path = PropertiesLoaderUtil.class.getClassLoader().getResource("").toURI().getPath();
        //String aa = path.replace("classes/", resourceName);
        //FileInputStream fis = new FileInputStream(new File(aa));  
	    InputStream fis = ClassLoader.getSystemResourceAsStream(resourceName);
        Properties props = new Properties();
        props.load(fis);
        fis.close();
        return props;
	}
   
	static Properties properties;
	 /**
     * 如果是在src下面，可以直接用springframework里面的PropertiesLoaderUtils直接去取
    * @Title: getProperties 
    * @Description: 加载properties文件 
    * @return Properties   
    * @throws
     */
    /*private static void getProperties(){
         try{
             if(properties.isEmpty()){
                 properties = PropertiesLoaderUtils.loadAllProperties("imconfig.properties");
             }
         }
         catch(Exception e){
             e.printStackTrace();;
         }
    }*/
    
	public static String getPropValue(String strKey) {
		if (null == properties) {
			try {
			    properties = loadAllProperties("system.properties");
			} catch (Exception e) {
				e.printStackTrace();
				return "";
			}
		}
		return properties.getProperty(strKey);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	    //System.out.println("C:" + File.separator + "tmp" + File.separator + "test.txt");
		System.out.println(PropertiesLoaderUtil.getPropValue("system.encoding"));
	}
}
